package com.zzsy.carosshopprojects.util;

import java.math.BigDecimal;

public class AlgorithmUtil {


    /**
     * 获取转换后的金额除
     *
     * @param orderAmount
     * @param multiple
     * @return
     */
    public static String getAmount(String orderAmount, int multiple) {
        if (StringUtils.isEmpty(orderAmount)) {
            orderAmount = "0";
        }
        return ConverterHelper.toBigDecimal(orderAmount).divide(ConverterHelper.toBigDecimal(multiple)).setScale(2, BigDecimal.ROUND_HALF_UP) + "";

    }

    /**
     * 获取转换后的金额乘
     *
     * @param orderAmount
     * @param
     * @return
     */
    public static String getMultiplyAmount(String orderAmount) {
        if (StringUtils.isEmpty(orderAmount)) {
            orderAmount = "0";
        }
        return ConverterHelper.toBigDecimal(orderAmount).multiply(ConverterHelper.toBigDecimal(100)).setScale(0, BigDecimal.ROUND_HALF_UP)+"";

    }

    /**
     * 减法
     * @param
     * @return
     */
    public static String getSubtractAmount(String str1,String str2) {

        return ConverterHelper.toBigDecimal(str1).subtract(ConverterHelper.toBigDecimal(str2)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

    }

    /**
     * 解析时间
     *
     * @param createTime
     * @param multiple
     * @return
     */
    public static String getTime(String createTime, int multiple) {
        if (StringUtils.isEmpty(createTime)) {
            createTime = "0";
        }
        return FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(createTime) / multiple), "yyyy-MM-dd HH:mm:ss");
    }

}
